package com.ls.modules.sys.dal.neo4j.entity;


import lombok.Data;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;

import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author: xiaosu
 * @date: 2018-09-21  18:10
 */

@Data
@NodeEntity
public class FamilyEntity {

    @Id
    @GeneratedValue
    private Long id;


    private  String name;


    private  String phone;


    private  String gender;


    @Relationship(type = "qinren", direction = Relationship.INCOMING)
    public Set<FamilyEntity> qinrens;

    public void qinWith(FamilyEntity familyEntity) {
        if (qinrens == null) {
            qinrens = new HashSet<>();
        }
        qinrens.add(familyEntity);
    }

    @Override
    public String toString() {
        return this.name + "'s qinrens => "
                + Optional.ofNullable(this.qinrens).orElse(
                Collections.emptySet()).stream()
                .map(FamilyEntity::getName)
                .collect(Collectors.toList());
    }



    private  FamilyEntity() {
    }

    public FamilyEntity( String name, String phone, String gender) {
        this.name = name;
        this.phone = phone;
        this.gender = gender;
    }
}
